import { createRouter, createWebHashHistory, useRouter } from 'vue-router'
export const currentRouter = useRouter()
const routes = [
  {
    path: '/',
    name: 'home',
    meta: {
      title: '首页'
    },
    component: () => import('../view/home.vue')
  },
  {
    path: '/beforeRoute',
    name: 'guard',
    meta: {
      title: '守卫学习'
    },
    component: () => import('../components/Route/beforeRoute.vue')
  },
  {
    path: '/routerLearning',
    name: 'router',
    meta: {
      title: '路由学习'
    },
    component: () => import('../components/Route/useRouteAnduseRouter.vue')
  },
  {
    // path: "*",
    path: '/:catchAll(.*)',
    name: 'NotFound',
    component: () => import('../view/404.vue'),
    meta: {
      requiresAuth: false
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  next()
  // document.title = `${to.meta.title} | vue-manage-system`
  // const role = localStorage.getItem('ms_username')
  // if (!role && to.path !== '/login') {
  //     next('/login')
  // } else {
  //     next()
  // }
})

export default router